/*
 * Copyright (c) 田梓萱 2021-2022.
 * All Rights Reserved.
 * All codes are protected by China's regulations on the protection of computer software, and infringement must be investigated.
 * 版权所有 (c) 田梓萱 2021-2022.
 * 所有代码均受中国《计算机软件保护条例》保护，本项目已获得软著.
 */

package com.xcl.calculator.Ability;

import com.xcl.calculator.Preference_RW;
import com.xcl.calculator.XLog;
import com.xcl.calculator.slice.Instruction.JieShao0AbilitySlice;
import com.xcl.calculator.slice.MainAbilitySlice;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;
import ohos.agp.utils.Color;
import ohos.agp.window.service.Window;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

/**
 * The type Main ability.
 *
 * @author Xcl
 * @date 2021 /12/29
 * @package com.xcl.calculator.Ability
 */
public class MainAbility extends Ability {
    /**
     * The constant label.
     */
    private static final HiLogLabel label = new HiLogLabel(HiLog.LOG_APP, 0x00234, "MainAbility");

    /**
     * 开始
     *
     * @param intent the intent
     */
    @Override
    public void onStart(Intent intent) {
        try {
            super.setAbilitySliceAnimator(null);
            super.setTransitionAnimation(0, 0);
            Window window = this.getWindow();
            window.setStatusBarColor(Color.rgb(0, 0, 0));
            window.setStatusBarVisibility(Component.VISIBLE);
            super.onStart(intent);
            if (Preference_RW.ff1_r() == 2) {
                super.setAbilitySliceAnimator(null);
                super.setTransitionAnimation(0, 0);
                //super.setMainRoute(CaiDanAbilitySlice.class.getName());
                /*无参--页面跳转开始*/
                Intent intent1 = new Intent();
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName(this.getBundleName())
                        .withAbilityName("com.xcl.calculator.Ability.CaiDanAbility")
                        .build();// 通过Intent中的OperationBuilder类构造operation对象，指定设备标识（空串表示当前设备）、应用包名、Ability名称
                intent1.setOperation(operation);// 把operation设置到intent中
                this.startAbility(intent1);
                /*页面跳转结束--无参*/
                this.onBackPressed();
                super.setAbilitySliceAnimator(null);
                super.setTransitionAnimation(0, 0);
            } else if (Preference_RW.ff1_r() == 1) {
                super.setAbilitySliceAnimator(null);
                super.setTransitionAnimation(0, 0);
                super.setMainRoute(JieShao0AbilitySlice.class.getName());
                super.setAbilitySliceAnimator(null);
                super.setTransitionAnimation(0, 0);
            } else {
                super.setAbilitySliceAnimator(null);
                super.setTransitionAnimation(0, 0);
                super.setMainRoute(MainAbilitySlice.class.getName());
                super.setAbilitySliceAnimator(null);
                super.setTransitionAnimation(0, 0);
            }
        } catch (Exception e) {
            XLog.pd_pd = Preference_RW.ff7_r();
            XLog.error(label, e.getMessage());
        }
    }
}
